/**
 * 
 */
package com.firebird.oms.web.dwr.sm;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.firebird.base.domain.Page;
import com.firebird.oms.domain.sm.TismFunction;
import com.firebird.oms.domain.sm.TismRole;
import com.firebird.oms.service.sm.AuthService;
import com.firebird.oms.web.base.BaseDwr;

/**
 * @author qiuxj
 * @date 2009-11-24
 *
 */
public class RoleDwr extends BaseDwr {
	
	private AuthService authService;

	/**
	 * 取得角色方法
	 * 
	 * @param roleId
	 * @return
	 */
	public TismRole getTismRole(int roleId) {
		return authService.getTismRole(roleId);
	}

	/**
	 * 取得角色及其关联权限方法
	 * 
	 * @param roleId
	 * @return
	 */
	public TismRole getTismRoleAndExt(int roleId) {
		return authService.getTismRoleAndExt(roleId);
	}

	/**
	 * 创建角色方法
	 * 
	 * @param smRole
	 * @return
	 */
	public Serializable createRole(TismRole smRole) {
		return authService.createRole(smRole);
	}

	/**
	 * 更新角色方法
	 * 
	 * @param smRole
	 */
	public void updateRole(TismRole smRole) {
		smRole.setFunctions(authService.getTismRoleAndExt(smRole.getRoleId()).getFunctions());
		authService.updateRole(smRole);
	}

	/**
	 * 更新角色及其关联权限方法
	 * 
	 * @param roleId
	 * @param functions
	 */
	public void updateRoleAndExt(int roleId, List<TismFunction> functions) {
		TismRole smRole = authService.getTismRole(roleId);
		smRole.setFunctions(new HashSet<TismFunction>(functions));
		authService.updateRole(smRole);
	}

	/**
	 * 分页查询角色方法
	 * 
	 * @param filter
	 * @param like
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public Page pageRole(Map<String, String> filter, Map<String, String> like, Map<String, String> sort, int pageNo,
			int pageSize) {
		return authService.pageRole(filter, like, pageNo, pageSize);
	}

	public List<TismRole> findRoleByFilter(Map<String, String> filter) {
		return authService.findRole(filter);
	}

	public void setAuthService(AuthService authService) {
		this.authService = authService;
	}

}
